package com.edushare.common.dao;

import java.util.Date;

import com.edushare.common.orm.ORMInterface;
import com.edushare.common.vo.FileUploadInfo;

public class FileUploadInfoDAO extends CayenneBasedDAO {

	public FileUploadInfoDAO(ORMInterface ormInterface) {
		super(ormInterface);
	}
	
	public void createFileUploadInfo(FileUploadInfo fuvo){
		getDataContext().registerNewObject(fuvo);
		getDataContext().commitChanges();
	}

	public void saveFileUploadInfo(FileUploadInfo fuvo) {
			//This code may not be safe:: Data context may have uncommited objects which may casue this update to fail
		    //TODO: make a safe atomic update for this object
		getDataContext().commitChanges();
	}

	public FileUploadInfo createFileUploadInfo(String clientFileName) {
		FileUploadInfo fuvo = getDataContext().newObject(FileUploadInfo.class);
		fuvo.setFileOrigName(clientFileName);
		fuvo.setUploadStatus(FileUploadInfo.UPLOAD_STATUS_PREUPLOAD);
		fuvo.setUploadTimestamp(new Date(System.currentTimeMillis()));
		getDataContext().commitChanges();
		return fuvo;
	}

}
